<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Handlers\WeconHandler;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class DedustingPointRange extends Model
{
    protected $table = 'xfy_dedusting_point_ranges';

    const RANGE_CACHE_KEY = 'dedusting_point_ranges_';

    public function device()
    {
        return $this->belongsTo(DedustingDevice::class);
    }

    public static function setCache($deviceId, $data)
    {
        $key = self::RANGE_CACHE_KEY.$deviceId;

        Redis::Set($key, $data);
    }

    public static function getCache($deviceId)
    {
        $key = self::RANGE_CACHE_KEY.$deviceId;
        $settings = Redis::Get($key);
        $settings = Redis::Get($key) ? json_decode($settings,true) : [];
        return $settings;
    }
}